package vip.xiaonuo.modular.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.modular.bloginfo.entity.BlogInfo;
import vip.xiaonuo.modular.bloginfo.service.BlogInfoService;
import vip.xiaonuo.sys.modular.consts.entity.SysConfig;
import vip.xiaonuo.sys.modular.consts.service.SysConfigService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liu
 */
@RestController
@RequestMapping("/front")
public class FrontController {

    @Resource
    private SysConfigService configService;
    @Resource
    private BlogInfoService blogInfoService;

    @GetMapping("/site/info")
    public ResponseData info() {
        Map<Object, Object> map = new HashMap<>(10);
        List<Map<String, Object>> maps = configService.blogConfigListMaps();
        for (Map<String, Object> itemMap : maps) {
            map.put(itemMap.get("code"),itemMap.get("value"));
        }

/*        QueryWrapper<SysConfig> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.lambda().eq(SysConfig::getCode, "avatar");
        map.put("avatar",configService.getOne(queryWrapper1).getValue());

        QueryWrapper<SysConfig> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.lambda().eq(SysConfig::getCode, "domain");
        map.put("domain",configService.getOne(queryWrapper2).getValue());

        QueryWrapper<SysConfig> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.lambda().eq(SysConfig::getCode, "notice");
        map.put("notice",configService.getOne(queryWrapper3).getValue());

        QueryWrapper<SysConfig> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.lambda().eq(SysConfig::getCode, "desc");
        map.put("desc",configService.getOne(queryWrapper4).getValue());

        QueryWrapper<SysConfig> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.lambda().eq(SysConfig::getCode, "slogan");
        map.put("slogan",configService.getOne(queryWrapper5).getValue());

        QueryWrapper<SysConfig> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.lambda().eq(SysConfig::getCode, "blogname");
        map.put("blogname",configService.getOne(queryWrapper6).getValue());

        QueryWrapper<SysConfig> queryWrapper7 = new QueryWrapper<>();
        queryWrapper7.lambda().eq(SysConfig::getCode,"copyright");
        map.put("copyright",configService.getOne(queryWrapper7).getValue());*/

        return new SuccessResponseData(map);
    }
    @GetMapping("/focus/list")
    public ResponseData focus() {
        QueryWrapper<BlogInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().select(BlogInfo::getBlogId,BlogInfo::getBlogTitle,BlogInfo::getBanner);
        wrapper.lambda().eq(BlogInfo::getIsTop,1);
        wrapper.lambda().orderByDesc(BlogInfo::getCreateTime);
        wrapper.lambda().eq(BlogInfo::getBlogStatus,1);
        List<BlogInfo> list = blogInfoService.list(wrapper);
        return new SuccessResponseData(list);
    }

}

